import { MyPromotion } from './myPromotion-model.js'
const app = getApp()
const promotion = new MyPromotion()
Page({
    /**
     * 页面的初始数据
     **/
    data: {
        QRCode: null,
        showPage: false,
        income: null
    },
    /*
    * 生命周期函数--监听页面加载
    */
    onLoad: function (options) {
        wx.showLoading({
            title: '加载中...',
        })
        let that = this;
        this.initLoad();

        this.setData({
            roleId: wx.getStorageSync("roleId")
        })
    },
    initLoad() {
        let pramas = {
            "page": "pages/index/index",
            "scene": wx.getStorageSync('phone')
        }
        promotion.getQRCode(pramas, res => {
            if (res.status) {
                wx.hideLoading();
                let data = res.data;
                this.setData({
                    QRCode: data.imgUrl,
                    showPage: true
                })
            }
        })
    },
    imgPreview() {
        let imgUrl = this.data.QRCode;
        wx.previewImage({
            current: imgUrl, // 当前显示图片的http链接
            urls: [imgUrl] // 需要预览的图片http链接列表
        })
    },
    onShow() {
        promotion.getIncome({}, res => {
            if (res.status) {
                this.setData({
                    income: res.data
                })
                console.log('推广佣金', res.data)
            } else {
                wx.showToast({
                    title: res.message,
                    icon: 'none'
                })
            }
        })
    },
    getMoney() {
        wx.showToast({
            title: '暂未开通',
            icon: 'none'
        })
    }
})